package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 游记
 */
@Getter@Setter
public class Travel extends BaseDomain{
    public static final int STATE_COMMON=0;//草稿
    public static final int STATE_AUDIT=1;//待审核
    public static final int STATE_RELEASE=2;//已发布
    public static final int STATE_REJECT=-1;//拒绝
    //标题
    private String title;
    //出行时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date travelTime;
    //人均消费
    private String perExpends;
    //出行天数
    private Integer days;
    //参与人数
    private Integer person;
    //作者
    private User author;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GTM+8")
    private Date createTime;
    //发布时间
    private Date releaseTime;
    //是否公开
    private Boolean isPublic=false;
    //地区
    private Region place;
    //封面
    private String coverUrl;
    //更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;
    //状态
    private Integer state=STATE_COMMON;

    //游记内容
    private  TravelContent travelContent;

    //浏览次数
    private int watchNum;

    //评论次数
    private int visitNum;



    //页面状态汉字回显
    public String getStateName() {
        String msg="草稿";
        if (state==Travel.STATE_AUDIT) {
            msg="待审核";
        }else if (state==Travel.STATE_RELEASE){
            msg="已发布";
        }else if (state==Travel.STATE_REJECT){
            msg="拒绝";
        }
        return msg;
    }


    //页面状态汉字回显
    public String getPersonName() {
        if(person!=null){
            String msg="和其他";
            if (person==1) {
                msg="一个人的旅行";
            }else if (person==2){
                msg="和父母";
            }else if (person==3){
                msg="和朋友";
            }else if (person==4){
                msg="和同事";
            }else if (person==5) {
                msg = "和爱人";
            }
            return msg;
        }
        return null;
    }

    /**
     * 增加一个属性 json对象
     * @return
     */
    public String getJson() {
        Map<String,Object> map= new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }






}